package org.android.cosmus.indiam.views;

import org.android.cosmus.indiam.R;
import org.android.cosmus.indiam.utilities.Utils;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

public class CustomArrayAdapter extends BaseAdapter
{
  private LayoutInflater mInflater;
  private Context context;
  private String[] data;

  public CustomArrayAdapter(Context context, String[] menuArray)
  {
    mInflater = LayoutInflater.from(context);
    data = menuArray;
    this.context = context;
  }

  @Override
  public int getCount()
  {
    return data.length;
  }

  @Override
  public Object getItem(int position)
  {
    return data[position];
  }

  @Override
  public long getItemId(int arg0)
  {
    return 0;
  }

  public View getView(final int position, View convertView, ViewGroup parent)
  {
    ItemListView itemList;
    if (convertView == null)
    {
      convertView = mInflater.inflate(R.layout.item_list, null);
      itemList = new ItemListView(convertView);

      convertView.setTag(itemList);
    }
    else
    {
      itemList = (ItemListView) convertView.getTag();
    }

    itemList.setMainText(data[position]);
    itemList.setDescription(context.getString(R.string.item_list_information));
    int iconId = Utils.getResourceDrawableIdBasedOnName(context, data[position], "_icon");
    if(iconId != 0)
      itemList.setIcon(iconId);

    return convertView;
  }
}
